//  gcc -Ofast -g -Wall -ftree-parallelize-loops=4 rng.c -o rng
//  put ./rng1 2>&1 | sed 's/^/a/' for john the ripper for each letter
//  -O3 -fomit-frame-pointer -ftree-vectorize -fno-math-errno -msse2 -march=native -mtune=native

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

/* Initialize an array and pass it in to initstate. */
static char state1[26] = {
     'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
     'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
     'u', 'v', 'w', 'x', 'y', 'z'
};

static char state2[62] = {
     'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
     'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
     'u', 'v', 'w', 'x', 'y', 'z',
     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
     'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
     'U', 'V', 'W', 'X', 'Y', 'Z',
     '1', '2', '3', '4', '5', '6','7', '8', '9', '0'
};

uint16_t lcg8(uint8_t a, uint8_t c, uint8_t m, uint16_t state);
int check(char *p);

int main() {
   int ctr1, ctr2, ctr3, ctr4, ctr5, ctr6, ctr7, ctr8;
   uint16_t next_state1 = 1;
   uint16_t next_state2 = 2;
   uint16_t next_state3 = 3;
   uint16_t next_state4 = 4;
   uint16_t next_state5 = 5;
   uint16_t next_state6 = 6;
   uint16_t next_state7 = 7;
   uint16_t next_state8 = 8;
   char pass[9];

   for ( ctr1 = 0; ctr1 < 26; ctr1 ++ )
   {
    next_state1 = lcg8(27, 17, 26, next_state1);
    pass[0] = state1[next_state1];

    for ( ctr2 = 0; ctr2 < 62; ctr2 ++ )
    {
      next_state2 = lcg8(63, 17, 62, next_state2);
      pass[1] = state2[next_state2];

      for ( ctr3 = 0; ctr3 < 62; ctr3 ++ )
      {
       next_state3 = lcg8(63, 17, 62, next_state3);
       pass[2] = state2[next_state3];
       
       for ( ctr4 = 0; ctr4 < 62; ctr4 ++ )
       {
        next_state4 = lcg8(63, 17, 62, next_state4);
        pass[3] = state2[next_state4];
	
	for ( ctr5 = 0; ctr5 < 62; ctr5 ++ )
        {
         next_state5 = lcg8(63, 17, 62, next_state5);
         pass[4] = state2[next_state5];
	 
	 for ( ctr6 = 0; ctr6 < 62; ctr6 ++ )
         {
          next_state6 = lcg8(63, 17, 62, next_state6);
          pass[5] = state2[next_state6];

	  for ( ctr7= 0; ctr7 < 62; ctr7 ++ )
          {
           next_state7 = lcg8(63, 17, 62, next_state7);
           pass[6] = state2[next_state7];

  	   for ( ctr8 = 0; ctr8 < 62; ctr8 ++ )
           {
            next_state8 = lcg8(63, 17, 62, next_state8);
            pass[7] = state2[next_state8];
	    pass[8] = '\0';

		if(check(pass)) 
		{
		  printf("%s\n", pass);
		}

           }
          }
         }
        }
       }
      }
    }
   }


   return EXIT_SUCCESS;
}

int check(char *p)
{
  int Decimal = 0;
  int Capital = 0;
  int i;

  for (i = 0; i < 8; i++)
  {
    if ( (((*(p+i) >= 65) && (*(p+i) <= 90))) ) Capital = 1;
    if ( (((*(p+i) >= 48) && (*(p+i) <= 57))) ) Decimal = 1;
  }

  if (Decimal && Capital) return 1;
  
  return 0;
}

uint16_t lcg8(uint8_t a, uint8_t c, uint8_t m, uint16_t state)
{ return (a*state + c) % m; }


